package yxy.game.pm2.chat.module;

import org.joda.time.DateTime;

import yxy.game.pm2.bean.area.ChatChannelType;
import yxy.game.pm2.message.ChatMessage;

public class ChatMsg {
	// bean===========================================================================
	private ChatChannelType channel;
	private DateTime time;
	private String msg;

	public ChatChannelType getChannel() {
		return channel;
	}

	public void setChannel(ChatChannelType channel) {
		this.channel = channel;
	}

	public DateTime getTime() {
		return time;
	}

	public void setTime(DateTime time) {
		this.time = time;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	// func===========================================================================

	public ChatMessage.ChatMsg pack() {
		ChatMessage.ChatMsg.Builder builder = ChatMessage.ChatMsg.newBuilder();
		builder.setText(getMsg());
		builder.setTime(getTime().getMillis());
		return builder.build();
	}

	static public ChatMsgPlayer create(String playerCode, ChatChannelType channel, String msg) {
		ChatMsgPlayer chatMsg = new ChatMsgPlayer();
		chatMsg.setPlayerCode(playerCode);
		chatMsg.setChannel(channel);
		chatMsg.setMsg(msg);
		chatMsg.setTime(DateTime.now());
		return chatMsg;
	}

	static public ChatMsg create(ChatChannelType channel, String msg) {
		ChatMsg chatMsg = new ChatMsg();
		chatMsg.setChannel(channel);
		chatMsg.setMsg(msg);
		chatMsg.setTime(DateTime.now());
		return chatMsg;
	}
}
